package com.atguigu.process.service.impl;

import com.atguigu.model.process.ProcessTemplate;
import com.atguigu.model.process.ProcessType;
import com.atguigu.process.mapper.OaProcessTypeMapper;
import com.atguigu.process.service.OaProcessTemplateService;
import com.atguigu.process.service.OaProcessTypeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 审批类型 服务实现类
 * </p>
 *
 * @author ws
 * @since 2024-01-16
 */
@Service
public class OaProcessTypeServiceImpl extends ServiceImpl<OaProcessTypeMapper, ProcessType> implements OaProcessTypeService {

    @Resource
    private OaProcessTemplateService oaProcessTemplateService;

    @Override
    public IPage<ProcessType> selectPage(Page<ProcessType> processTypePage) {
        return null;
    }

    /**
     * 查找所有的模板分类，以及相应的审批模板
     * @return
     */
    @Override
    public Object findProcessType() {
        List<ProcessType> processTypes = baseMapper.selectList(null);
        for (ProcessType processType : processTypes) {
            LambdaQueryWrapper<ProcessTemplate> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(ProcessTemplate::getProcessTypeId,processType.getId());
            List<ProcessTemplate> list = oaProcessTemplateService.list(wrapper);
            processType.setProcessTemplateList(list);
        }
        return processTypes;
    }
}
